package com.irdstudio.efp.nls.service.common.rules.apply;

import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.efp.nls.service.common.rules.CheckRule;
import com.irdstudio.efp.nls.service.vo.NlsApplyInfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 需求编号:2019D08--
 * 问题编号:
 * 开发人员: caoxin
 * 创建日期:2020/1/17
 * 功能描述:
 * 修改日期:2020/1/17
 * 修改描述:
 */
public class ValidateFormatDate implements CheckRule {
    private static Logger logger = LoggerFactory.getLogger(ValidateFormatDate.class);
    private String formatDate;

    public ValidateFormatDate(String formatDate) {
        this.formatDate = formatDate;
    }

    @Override
    public void check() throws BizException {
        try {
            if (formatDate == null || formatDate.equals("")) {
                logger.error("贷款申请时间不能为空!!!");
                throw new BizException("贷款申请时间不能为空!!!");
            }
            Pattern pattern = Pattern.compile("^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$");
            Matcher match = pattern.matcher(formatDate);
            if (match.matches() != true) {
                logger.error("贷款申请时间格式不正确!!!");
                throw new BizException("普税贷贷款申请时间格式不正确!!!");
            }
        } catch (Exception e) {
            logger.error("贷款申请校验出现错误",e);
        }
    }
}
